#lib imports 
import random
import pygame
from pygame.locals import *

#local imports
from game.game_data import GameData

class Rogue():
    def __init__(self):
        #gui.Desktop.__init__(self, **params)

        random.seed()
        pygame.init()

        self.data = GameData()

    def loop(self):

        for e in pygame.event.get():
            if e.type == QUIT:
                self._run = 0
                return
            else:
                if not self.data.gui.event(e):
                    self.data.state_mgr.current_state().event(e)

        tick = pygame.time.get_ticks() - self.last_tick
        self.last_tick = tick

        self._run = self.data.state_mgr.current_state().update(tick)
        self.data.state_mgr.current_state().draw(tick)
        pygame.display.flip()

    def run(self, delay=0):
        self._run = 1
        self.last_tick = pygame.time.get_ticks()
        while self._run:
            self.loop()
            pygame.time.wait(delay)


app = Rogue()
app.run()